package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.TbLessee;
import com.ruoyi.system.service.ITbLesseeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 租户Controller
 * 
 * @author ruoyi
 * @date 2023-04-24
 */
@RestController
@RequestMapping("/lessee")
public class TbLesseeController extends BaseController
{
    @Autowired
    private ITbLesseeService tbLesseeService;

    /**
     * 查询租户列表
     */
    @RequiresPermissions("    ")
    @GetMapping("/list")
    public TableDataInfo list(TbLessee tbLessee)
    {
        startPage();
        List<TbLessee> list = tbLesseeService.selectTbLesseeList(tbLessee);
        return getDataTable(list);
    }

    /**
     * 导出租户列表
     */
    @RequiresPermissions("system:lessee:export")
    @Log(title = "租户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbLessee tbLessee)
    {
        List<TbLessee> list = tbLesseeService.selectTbLesseeList(tbLessee);
        ExcelUtil<TbLessee> util = new ExcelUtil<TbLessee>(TbLessee.class);
        util.exportExcel(response, list, "租户数据");
    }

    /**
     * 获取租户详细信息
     */
    @RequiresPermissions("system:lessee:query")
    @GetMapping(value = "/{lesseeId}")
    public AjaxResult getInfo(@PathVariable("lesseeId") Long lesseeId)
    {
        return success(tbLesseeService.selectTbLesseeByLesseeId(lesseeId));
    }

    /**
     * 新增租户
     */
    @RequiresPermissions("system:lessee:add")
    @Log(title = "租户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbLessee tbLessee)
    {
        return toAjax(tbLesseeService.insertTbLessee(tbLessee));
    }

    /**
     * 修改租户
     */
    @RequiresPermissions("system:lessee:edit")
    @Log(title = "租户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbLessee tbLessee)
    {
        return toAjax(tbLesseeService.updateTbLessee(tbLessee));
    }

    /**
     * 删除租户
     */
    @RequiresPermissions("system:lessee:remove")
    @Log(title = "租户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lesseeIds}")
    public AjaxResult remove(@PathVariable Long[] lesseeIds)
    {
        return toAjax(tbLesseeService.deleteTbLesseeByLesseeIds(lesseeIds));
    }
}
